﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class cn_feedback : System.Web.UI.Page
{
    protected string _cid = "36"; protected string parentId = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        _cid = Request.QueryString["cid"]; parentId = Request.QueryString["parentId"];
        if (string.IsNullOrEmpty(_cid))
        {
            _cid = ColumnHelp.GetFirstColumnId(16);
        }
        else
        {
            if (!Whir.Common.WebHelper.Utils.IsInt(_cid))
                _cid = ColumnHelp.GetFirstColumnId(16);
        }
        if (!IsPostBack)
        {
            GetList();
            GetTipsInfo();
        }
        if (Session["UserName"] != null)
        {

            GetInfo();
        }
    }

    private void GetList()
    {
        AspNetPager1.PageSize = 6;
        string where = "TypeID=" + _cid + " and IsStatus='是'";
        string countSql = "SELECT COUNT(*) FROM Whir_U_Message WHERE " + where;
        AspNetPager1.RecordCount = int.Parse(Whir.SQLServerDAL.DbHelperSQL.GetSingle(countSql).ToString());
        DataTable dt = Whir.SQLServerDAL.DbHelperSQL.GetList("Whir_U_Message", "Whir_U_Message_PID", "*", AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex - 1, where, "", "CreateDate desc").Tables[0];
        rptList.DataSource = dt;
        rptList.DataBind();

    }
    protected void AspNetPager1_PageChanged1(object sender, EventArgs e)
    {
        GetList();
    }


    protected string GetReplayTime(string dateTime)
    {
        if (!string.IsNullOrEmpty(dateTime))
        {
            return string.Format("({0})", Convert.ToDateTime(dateTime).ToString("yyyy-MM-dd"));
        }

        return "";
    }
    private void GetInfo()
    {
        string sql = string.Format("select * from Whir_U_Users where LoginName='{0}' ", Session["UserName"].ToString());
        DataTable dt = Whir.SQLServerDAL.DbHelperSQL.Query(sql).Tables[0];
        if (dt != null && dt.Rows.Count > 0)
        {
            txtName.Value = dt.Rows[0]["TrueName"].ToString();
            txtTel.Value = dt.Rows[0]["LinkTel"].ToString();
            txtEmail.Value = dt.Rows[0]["Email"].ToString();
            txtCompany.Value = dt.Rows[0]["CompanyName"].ToString();
        }

    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        string sql = "insert into Whir_U_Message (TypeID,CreateDate,Person,Tel,Email,Title,Content,CompanyName) values (@TypeID,@CreateDate,@Person,@Tel,@Email,@Title,@Content,@CompanyName)";
        SqlParameter[] pa =
        {
            new SqlParameter("@TypeID",_cid),
            new SqlParameter("@CreateDate",DateTime.Now),
            new SqlParameter("@Person",txtName.Value),
            new SqlParameter("@Tel",txtTel.Value),
            new SqlParameter("@Email",txtEmail.Value),
            new SqlParameter("@Title",txtSubject.Value),  
            new SqlParameter("@Content",txtContent.Value),
            new SqlParameter("@CompanyName",txtCompany.Value)
        };
        int count = Whir.SQLServerDAL.DbHelperSQL.ExecuteSql(sql, pa);
        if (count > 0)
        {

            Whir.Common.WebHelper.JsHelper.redirect(this.Page, "发送成功!", "feedback.aspx?cid=" + _cid + "&parentId=" + parentId);


        }
        else { Whir.Common.WebHelper.JsHelper.Alert(this.Page, "发送失败!"); }
    }


    private void GetTipsInfo()
    {
        if (_cid == "19" || _cid == "23" || _cid == "27" || _cid == "35")
        {
            Response.Redirect(string.Format("feedback4.aspx?cid={0}&parentId={1}", _cid, parentId));
        }
        ltrTips.Text = ColumnHelp.GetColumnName(_cid);
    }
}
